<?php
    namespace wzh\tcfxapi;
    class Team {
        public $jsondata;

        /**获取景区详情
         * @return bool|mixed
         * eg|json:
         */
        public function GetSceneryDetail() {
            $tongcheng = new Tongcheng();
            $jsondata = $this->jsondata;
            $data = array();
            $data['sceneryId'] = $jsondata['sceneryId'];//同程产品id
            $response = $tongcheng->request($data, 'GetSceneryDetail');
            Tongcheng::writelog($response, 'info', 'GetSceneryDetail.log');//失败写入日志。
            $response = json_decode($response, true);
            var_dump($response);
            if (empty($response) || !isset($response['SceneryID'])){
                Tongcheng::writelog($response, 'error', 'GetSceneryDetail.log');//失败写入日志。
            }
            return $response;
        }
        /**获取产品
         * @return bool|mixed
         * eg|json:{
         * "totalCount": 2,
         * "ticketPriceList": [{
         * "ticketPriceId": 120021,"ticketName": "蒙阴地下银河成人票（含漂流）","effectiveBeginDate": "2014-11-7 0:00:00","effectiveEndDate": "2015-12-31 23:59:59",
         * "startSellDate": "2014-11-07""stopSellDate": "2015-12-31","exceptDate": [],"sceneryId": 24968"sceneryName": "蒙阴地下银河景区",
         * "marketPrice": 70,"tcAmountPrice": 45,"agentPrice": 40,"isRealName": false,"isNeedIdCard": false,"minSaleQty": 1,"maxSaleQty": 99,
         * "reserveBeforeDays": 0,"reserveBeforeTime": "17:00","reserveType": 0,"reserveTimes": 0,"reserveTotalTickets": 0,"reserveDaysLimit": 0,"reservecheckWay": "60501",
         * "isIntelligent": true,"isNeedMail": true,"isPassport": false,"isScreening": false,"isPass": false,"IsPost": false,"isReMark": false,
         * "containedItems": "包含项目说明","getTicketMode": "取票方式说明","consumers": 60301,"consumersName": "成人票"
         * }]
         * }
         */
        public function GetTicketDetail($jsondata) {
            $tongcheng = new Tongcheng();
            $jsondata = $jsondata?:$this->jsondata;
            $data = array();
            $pageSize=isset($jsondata['pageSize'])?$jsondata['pageSize']:10;
            $data['pageSize'] = ($pageSize > 20) ? 20 : $pageSize;//最大单次获取数量为20
            $data['pageIndex'] = empty($jsondata['pageIndex'])?1:$jsondata['pageIndex'];//页面索引
            isset($jsondata['s_id']) && $data['priceId'] = $jsondata['s_id'];//同程产品id
            //$data['sceneryId']=30911;//目前不支持景区id查询
            //$data['sceneryName'] = $jsondata[''];//景区名称
            //$data['ticketName'] = '测试';//门票名城
            $response = $tongcheng->request($data, 'GetTicketDetail');
            Tongcheng::writelog($response, 'info', 'GetTicketDetail.log');//失败写入日志。
            $response = json_decode($response, true);
            if (empty($response) || !isset($response['ticketPriceList'])){
                Tongcheng::writelog($response, 'error', 'GetTicketDetail.log');//失败写入日志。
            }
            return $response;
        }

        /**
         *获取产品增量查询,我方定时查询或指定id手动查询
         * @return mixed|string
         * eg:json:
         *{
         * "respCode": 1,
         * "respMsg": "获取数据成功",
         * "respTime": "2014-5-24 13:01:25",
         * "maxIncrementId": 1000,
         * "ticketPriceList": [{
         * "ticketPriceId": 120021,"ticketName": "蒙阴地下银河成人票（含漂流）","effectiveBeginDate": "2014-11-7 0:00:00","effectiveEndDate": "2015-12-31 23:59:59",
         * "startSellDate": "2014-11-07","stopSellDate": "2015-12-31","exceptDate": [],"sceneryId": 24968,"sceneryName": "蒙阴地下银河景区",
         * "marketPrice": 70,"tcAmountPrice": 45,"agentPrice": 40,"isRealName": false,"isNeedIdCard": false,"minSaleQty": 1,"maxSaleQty": 99,
         * "reserveBeforeDays": 0,"reserveBeforeTime": "17:00","reserveType": 0,"reserveTimes": 0,"reserveTotalTickets": 0,"reserveDaysLimit": 0,"reservecheckWay": "60501",
         * "isIntelligent": true,"isNeedMail": true,"isPassport": false,"isScreening": false,"isPass": false,"IsPost": false,"isReMark": false,
         * "containedItems": "包含项目说明","getTicketMode": "取票方式说明","consumers": 60301,"consumersName": "成人票"
         * }]
         * }
         */
        public function GetTicketIncrement() {
            return self::QueryIncrement();
        }

        /**增量查询接口返回
         * @param string $type
         * @return mixed|string
         */
        function QueryIncrement($type = 'GetTicketIncrement') {
            $tongcheng = new Tongcheng();
            $jsondata = $this->jsondata;
            $data = array();
            $data['maxIncrementId'] = $jsondata['maxIncrementId'];//增量查询id
            $data['queryNumber'] = ($jsondata['queryNumber'] > 20) ? 20 : $jsondata['queryNumber'] ?: 20;//最大单次获取数量为20
            //仅产品变动增量查询可指定产品id获取指定产品id的详细信息
            if (isset($jsondata['s_id']) && ($type == 'GetTicketIncrement')){
                $data['priceId'] = $jsondata['s_id'];//同程产品id
            }
            $response = $tongcheng->request($data, $type);
            $response = json_decode($response, true);
            if (empty($response) || ($response['respCode'] != 1)) {
                Tongcheng::writelog($response, 'error', $type . '.log');//失败写入日志。
            }
            return $response;
        }

        /**
         * 产品下架查询接口，我方定时主动查询（任务）
         * @return bool|mixed
         * eg:json:
         *{
         * "respCode": 1,
         * "respMsg": "获取数据成功",
         * "respTime": "2014-5-24 13:01:25",
         * "maxIncrementId": 1000,
         * "ticketPriceId": [101,102,105,107]
         * }
         */
        public function OffLineGroupTicket() {
            return self::QueryIncrement('OffLineGroupTicket');
        }

        /**退改规则信息查询
         * @param $jsondata
         * @return mixed|string
         * @reparam backRule:退款规则；
         * @reparam RefundRuleList:退款规则列表；
         * @reparam IsRefund:是否全款退；
         * @reparam IsPartialRefund:是否部分退；
         * @reparam ChargeType:手续费类型；22301：单票手续费 22302： 总额手续费  22303：总额百分比手续费
         * @reparam Charge:手续费；
         * @reparam TCChargeType:同程手续费类型；
         * @reparam TCCharge:同城手续费；
         * @reparam Day:天数；负数为旅游日期提前，正数为旅游过期后
         * @reparam Hour:小时；
         * @reparam Minute:分钟；
         * eg|json:{
         * "respCode": 1,
         * "backRule": "退款规则： (1)本产品预订后订单支持退款，如未出游，您最晚于游玩日期后1天的0:00前申请，每退一张门票将收取6.21元手续费。
         * "RefundRuleList": [{"IsRefund": 1,"IsPartialRefund": 1,"ChargeType": 22301,"Charge": 2.66,"TCChargeType": 22301,"TCCharge": 3.55,"Day": 1,"Hour": 0,"Minute": 0 }]
         * }
         */
        public function GetRefundRule($jsondata=array()) {
           $jsondata=$jsondata?:$this->jsondata;
           $tongcheng = new Tongcheng();
            $data = array();
            $data['ViewSceneryRule'] = 0;//是否查询以景区来查询,固定为否，以产品id来查询
            $data['ProductID'] = $jsondata['s_id'];//产品id
            $response = $tongcheng->request($data, 'GetRefundRule');
            $response = json_decode($response, true);
            if (empty($response) || ($response['respCode'] != 1)) {
                Tongcheng::writelog($response, 'error', 'GetRefundRule.log');//失败写入日志。
            }
            return $response;
        }

        /**
         * 查询产品推改规则变动id接口，我方定时主动查询。 同产品下架接口
         * @return mixed|string
         * eg|json{
         * "respCode": 1,
         * "respMsg": "获取数据成功",
         * "respTime": "2014-5-24 13:01:25",
         * "maxIncrementId": 1000,
         * "ticketPriceId": [101,102,105,107]
         * }
         */
        public function RefundRuleChangeTicket() {
            return self::QueryIncrement('RefundRuleChangeTicket');
        }

        ///价格日历（任务或者接口调用时自动查询）
        public function GetPriceCalendarInfo() {
            $tongcheng = new Tongcheng();
            $jsondata = $this->jsondata;
            $data = array();
            $data['PriceId'] = $jsondata['s_id'];//产品id
            $data['TravelDate'] = $jsondata['start_date'];//开始日期2016-6-24
            $data['MonthNumber'] = $jsondata['month_num']?:1;//获取月份数量,默认一个月
            $response = $tongcheng->request($data, 'GetPriceCalendarInfo');
            $response = json_decode($response, true);
            if (empty($response) || ($response['respCode'] != 1)) {
                Tongcheng::writelog($response, 'error', 'GetPriceCalendarInfo.log');//失败写入日志。
            }
            return $response;
        }
    }